//
//  WSGTheStartView.m
//  oneDollar
//
//  Created by Laki on 16/7/1.
//  Copyright © 2016年 com.Laki.corder. All rights reserved.
//

#import "WSGTheStartView.h"
#import "WSGTheStartItem.h"

#import <UIImageView+WebCache.h>

@interface WSGTheStartView()
/** 图片*/
@property (weak, nonatomic) IBOutlet UIImageView *picUrlImageView;
/** 小时*/
@property (weak, nonatomic) IBOutlet UILabel *hourLabel;
/** 分钟*/
@property (weak, nonatomic) IBOutlet UILabel *minuteLabel;
/** 秒钟*/
@property (weak, nonatomic) IBOutlet UILabel *secondLabel;

@end

@implementation WSGTheStartView

/*
 * 快速加载视图
 */
+ (instancetype)loadTheStartView{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].firstObject;
}

/*
 * 设置模型数据
 */
- (void)setItem:(WSGTheStartItem *)item{
    _item = item;
    
    // 设置图片
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:item.picUrl] placeholderImage:[UIImage imageNamed:@"Circle_BackgroundBigImage"]];
    
    // 设置时间
    [self reloadTimer];
    
}

/*
 * 设置时间数据
 */
- (void)reloadTimer{
    
    // 换算小时
    NSInteger hourLabel = [_item.leftSeconds intValue] / (60 * 60);
    
    // 总小时秒数
    NSInteger hourTotal = hourLabel * 60 * 60;
    
    // 换算分钟
    NSInteger minuteLabel = ([_item.leftSeconds intValue] - hourTotal) / 60;
    
    // 换算秒钟
    NSInteger secondLabel = ([_item.leftSeconds intValue] - hourTotal) % 60;
    
    // 每个字符中间距
    NSDictionary *dictAttr = @{NSKernAttributeName:@(11)};
    
    // 设置时钟
    self.hourLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%02zd",hourLabel] attributes:dictAttr];
    
    // 设置分钟
    self.minuteLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%02zd",minuteLabel] attributes:dictAttr];
    
    // 设置秒钟
    self.secondLabel.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%02zd",secondLabel] attributes:dictAttr];
}

@end
